﻿///***************************************************************
/// 시  스  템 : Updms.Bby
/// 단위시스템 : BBY
/// 계      층 : Presentation Layer
/// 프로그램명 : Bby2010r
/// 파  일  명 : Bby2010r.aspx.cs
/// 설      명 : 일별수유챠트
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-08-13 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web.UI;

using SMFramework.Data;
using SMFramework.Utility;

using Base.Dac;
using Updms.Bby.Exe;


namespace Updms.Bby
{
	public partial class Bby2010r : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Bby2010r";
		public static readonly string gs_path_info = "/updms/Bby/" + PID + ".aspx";

		Global global = new Global();

		//검색
		protected string kw1 = "";	// 수유일 ~부터
		protected string kw2 = "";	// 수유일 ~까지

		//메뉴 선택값
		protected string gs_sm = "";

		// 페이지모드
		private string gs_page_mode = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetInit, SetClientScript

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}		

		private void SetClientScript()
		{
			//onKeyPress이벤트 (엔터검색)
			txt_search_lac_dt_from.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
			txt_search_lac_dt_to.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
		}

		#endregion

		#region SetSearchParameter, ShowKeywordLabel

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 없으면
					{
						kw1 = String.IsNullOrEmpty(txt_search_lac_dt_from.Text) ? DateUtil.GetMonthEx(-5) : txt_search_lac_dt_from.Text.Trim();
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						txt_search_lac_dt_from.Text = kw1;
					}


					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))	// url에 값이 없으면
					{
						kw2 = String.IsNullOrEmpty(txt_search_lac_dt_to.Text) ? DateUtil.GetMonthEx(0) : txt_search_lac_dt_to.Text.Trim();
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						txt_search_lac_dt_to.Text = kw2;
					}
					break;
				case "SEARCH":
					kw1 = String.IsNullOrEmpty(txt_search_lac_dt_from.Text) ? DateUtil.GetMonthEx(-5) : txt_search_lac_dt_from.Text.Trim();
					kw2 = String.IsNullOrEmpty(txt_search_lac_dt_to.Text) ? DateUtil.GetMonthEx(0) : txt_search_lac_dt_to.Text.Trim();

					break;
			}
		}

		#endregion

		#region 챠트 (DrawDailyLactationList, SearchProcess)

		//조회
		private void DrawDailyLactationList()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			//초기화
			chart_daily_list.Data.Clear();
			
			//시리즈
			chart_daily_list.Data.Series = 2;
			chart_daily_list.Series[0].Text = "수유량";
			chart_daily_list.Series[1].Text = "실제수유량";

			//검색
			lo_dp.AddProperty("ls_lac_dt_from", typeof(string), kw1);
			lo_dp.AddProperty("ls_lac_dt_to", typeof(string), kw2);

			using (Bby2010r_NT _Bby2010r_NT = new Bby2010r_NT())
			{
				lo_ds.Merge(_Bby2010r_NT.GetDailyLactationList(lo_dp));
			}

			int li_count = DataSetUtil.GetRowCount(lo_ds, "UPDMS_BBY_REPORT");

			for (int i = 0; i < li_count; i++)
			{
				//수동으로 데이터 바인딩
				chart_daily_list.Data[0, i] = DataSetUtil.GetFldInt(lo_ds, "UPDMS_BBY_REPORT", i, "Cc");
				chart_daily_list.Data[1, i] = DataSetUtil.GetFldInt(lo_ds, "UPDMS_BBY_REPORT", i, "Real_Cc");

				//X축 라벨링 (2008-01-01 -> '08.01.01)
				string ls_lac_dt = "'" + DataSetUtil.GetFldStr(lo_ds, "UPDMS_BBY_REPORT", i, "Lac_Dt").Substring(2, 8).Replace("-", ".");
				chart_daily_list.AxisX.Labels[i] = ls_lac_dt;
			}
		}

		//검색
		private void SearchProcess()
		{
			gs_page_mode = "R";
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();

			DrawDailyLactationList();
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			switch (gs_page_mode)
			{
				case "":		// 처음 페이지로드시
					table_chart.Visible = false;	// line챠트
					break;
				case "R":	// 검색버튼 클릭시
					table_chart.Visible = true;	// line챠트
					break;
			}
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_chart_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}	

		#endregion

	}
}
